﻿using Smobiler.Core;
using Smobiler.Core.Controls;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using FubiManger.UI;

namespace FubiManger.Controls
{
    ////ToolboxItem用于控制是否添加自定义控件到工具箱，true添加，false不添加
    //[System.ComponentModel.ToolboxItem(true)]
    partial class Updateimgcontrol : Smobiler.Core.Controls.MobileUserControl
    {
        public Updateimgcontrol() : base()
        {
            //This call is required by the SmobilerUserControl.
            InitializeComponent();
        }
        /// <summary>
        /// 编号
        /// </summary>
        public int index { get; set; }
        /// <summary>
        /// 1商品2活动
        /// </summary>
        public string stype { get; set; }
        private void camera1_ImageCaptured(object sender, BinaryResultArgs e)
        {
            if (e.isError == false)
            {

                string name = DateTime.Now.ToString("yyyyMMddHHmmssms") + Getcode() + ".png";
                e.SaveFile(name, @"C:\fbimage\");
                if (stype == "1")
                    ((AddgoodForm)this.Form).Updateimg(index, name);
                else
                    ((AddactivityForm)this.Form).Updateimg(index, name);

                this.Close();
            }
        }
        /// <summary>
        /// 随机4位数
        /// </summary>
        /// <returns></returns>
        private int Getcode()
        {
            Random rand = new Random();
            return rand.Next(1000, 9999);
        }
        private void btnupdate_Press(object sender, EventArgs e)
        {
            camera1.GetPhoto();
        }

        private void btndel_Press(object sender, EventArgs e)
        {
            if (stype == "1")
                ((AddgoodForm)this.Form).Delimg(index);
            else if(stype=="2")
                ((AddactivityForm)this.Form).Delimg(index);
            this.Close();
        }

        private void btnclose_Press(object sender, EventArgs e)
        {
            this.Close();
        }
    }
}